/* Controller */

#import <Cocoa/Cocoa.h>

@interface Controller : NSObject
{
    IBOutlet NSPopUpButton *channelsBox;
    IBOutlet NSPopUpButton *providersBox;
	IBOutlet NSTableView *programTable;
	IBOutlet NSTableView *currentProgramsTable;
	IBOutlet NSDatePicker * dateBox;
	IBOutlet NSTextField * statusText;
	IBOutlet NSProgressIndicator * progressIndicator;
	IBOutlet NSPanel * aboutPanel;
	IBOutlet NSTextField * titleFld;
	IBOutlet NSTextView * descTextView;
	IBOutlet NSTextView * currentDescTextView;
	IBOutlet NSScrollView *programScroll;
	IBOutlet NSScrollView *currentProgramsScroll;
	IBOutlet NSMatrix *applicationName;
	IBOutlet NSWindow *prefWindow;
	NSXMLDocument * xmlChannelDataDoc;
	bool isProgamTableSelected;
	
	//Preferences
	IBOutlet NSPopUpButton *channelsBoxPreferences;
    IBOutlet NSPopUpButton *providersBoxPreferences;
	IBOutlet NSTextField *minsBeforePreferences;
	IBOutlet NSTextField *minsAfterPreferences;
	IBOutlet NSTextField *adjustHoursPreferences;
	IBOutlet NSTextField *adjustMinsPreferences;
	IBOutlet NSTextField *postcodePreferences;
	IBOutlet NSTextField *clientIDPreferences;
	IBOutlet NSMatrix *applicationNamePreferences;
	
	NSMutableDictionary * m_providersCache;
	NSMutableArray * m_providersArrayCache;
	NSMutableDictionary * m_channelsCache;
	NSMutableArray * m_tableData;
	NSMutableArray * m_currentTableData;
	
	NSURLConnection * m_urlConnection;
	NSMutableData * m_urlData;
	NSConditionLock * m_urlDataLock;
	
	NSString *defaultProvider;	
	NSString *defaultRealProvider;
	NSString *defaultSelectedChannel;
	NSString *defaultChannelNumber;
	NSString *defaultChannelID;
	NSString *defaultApplication;
	NSString *defaultMinsBefore;
	NSString *defaultMinsAfter;
	NSString *defaultPostcode;
	NSString *defaultClientID;
	NSString *defaultAdjustHours;
	NSString *defaultAdjustMins;
	
	// NSXMLDocument
}



-(void)flagURLError:(NSString*)errorString;

-(void)applicationWillTerminate:(NSNotification *)notification;

-(NSArray*)getJustChannelNames:(NSString*)provider;

-(void)providersChanged:(id)sender;

-(void)providersChangedPreferences:(id)sender;

-(IBAction)tableViewSelected:(id)sender;

-(void)savePreferences;

-(void)updateDescInfo:(int)index tableView:(id)aTableView;

-(void)saveDefaultsPreferences:(id)sender;

-(void)restorePreferences;

-(BOOL)canAddToValidChannelListing:(NSString *)channel channelid:(NSString *)channelid theDate:(NSCalendarDate *)theDate entryDate:(NSCalendarDate *)entryDate title:(NSString *)title;

-(NSString*)getChannelName:(NSString *)channelID;

-(void)fillChannelArray;

-(NSString *)getXMLVal:(NSString *)anXMLkey element:(NSXMLElement *)element;

-(void)loadDefaultsIntoInterface;

- (IBAction)showPreferencesWindow:(id)sender;

-(void)visitDarylHomepageClicked:(id)sender;

-(NSDictionary *)getChannelDict;

-(NSString *)getITeleApplescript:(NSString*)title channelid:(NSString*)channelid callsign:(NSString*)callsign startdate:(NSCalendarDate*)startdate enddate:(NSCalendarDate*)enddate;

@end
